//
//  FenLeiController.swift
//  JianTingSwift
//
//  Created by zhibao on 2024/11/20.
//

import UIKit

class FenLeiController: SecSuperController,UITableViewDelegate,UITableViewDataSource,DataChangeDelegate {

    var fenleiDic = [String:String]()
    fileprivate var showTableView = MYTableView(frame: CGRectMake(0, navigationFullHeight(), SCREEN_WIDTH, SCREEN_HEIGHT - navigationFullHeight()), style: .plain)
    
    fileprivate var dataArray = [[String:String]]()
    override func viewDidLoad() {
        super.viewDidLoad()
        self.gk_navTitle = fenleiDic["title"]
        self.initTableview()
        self.getData()
    }
    fileprivate func initTableview(){
        showTableView.delegate = self
        showTableView.dataSource = self
        showTableView.dataChangeDelegate = self
        showTableView.separatorStyle = .none
        showTableView.register(ProjectCell.self, forCellReuseIdentifier: "ProjectCell")
        self.view.addSubview(showTableView)
        showTableView.noDataType = .TableViewNoDataType_FILE
        showTableView.mj_footer?.endRefreshingWithNoMoreData()
        self.getData()
    }
    
    func getData(){
        QMUITips.showLoading(in: self.view)
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
            QMUITips.hideAllTips()
            self.dataArray = shebeiDic[self.fenleiDic["type"] ?? ""] ?? []
            self.showTableView.reloadData()
        }
    }
}

extension FenLeiController {
    func refreshData(withTabelViewTag tableViewTag: Int) {
        self.getData()
    }
    
    func loadMoreData(withTabelViewTag tableViewTag: Int) {
        self.getData()
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataArray.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let dic = dataArray[indexPath.row]
        let cell = tableView.dequeueReusableCell(withIdentifier: "ProjectCell") as! ProjectCell
        cell.updata(dic: dic)
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let dic = dataArray[indexPath.row]
        let controller = ProjectDetailController()
        controller.dic = dic
        self.navigationController?.pushViewController(controller, animated: true)
    }
}
